#ifndef UI_H
#define UI_H
#include <gtk/gtk.h>

#include <semaphore.h>
#include "map.h"
#include "server.h"
#include "msgqueuelock.h"

typedef struct litte{
    GtkWidget * lb_id;//作为窗口复用
    GtkWidget * lb_msg;
    GtkWidget * text_view;
    void * data;
}FriendId;

Map map;//用以id、socket、窗口、lb、lbnum之间的映射
struct sockaddr_in address;
struct Msgqueue cqueue;//接受服务器发来的消息。基于10个数组的队列，内有信号量保持同步

extern int sockfd;//在server.c里面
extern gboolean connect_code;

gboolean exit_code;//为0表示，线程即将推出
gboolean ini_thread_code;

sem_t sign_lb_lock;
sem_t sign_text_view;

GtkWidget * et_id;  //登录框ID
GtkWidget * et_pass;//登录框口令
GtkWidget * lb_info;//信息框label
GtkWidget * lb_info_sour;//陌生人号
GtkWidget * friend_vbox;//众多好友
GtkWidget * head_image;//头像
GtkWidget * self_label;//昵称
GtkWidget * sign_label;//个人签名

GtkWidget * main_window;//主窗口
GtkWidget * login_window;//登录窗口
GtkWidget * info_window;//信息窗口
GtkWidget * add_window;
GtkWidget * dele_window;
GtkWidget * confirm_window;

void MainWindow();
void InfoWindow();
void LoginWindow();
void AddWindow();
void DeleWindow();
void ConfirmWindow();
void ChatWindow(GtkWidget **from_window, GtkWidget **from_text_view);
void AddMessage(int id, const char *msg);

/***********************event**********************/
void exit_event(GtkWidget *widget, gpointer data);
void login_event(GtkWidget *widget, GdkEvent *event,gpointer data);
void regi_event(GtkWidget *widget,GdkEvent *event, gpointer data);
void info_event(GtkWidget *widget, gpointer data);
void creat_chat_event(GtkWidget *widget,GdkEvent *event,gpointer data );
void hide_chat_window_event(GtkWidget *widget,GdkEvent *event,gpointer data);
void send_msg_event(GtkWidget *widget,GdkEvent *event, gpointer data);

void show_add_event(GtkWidget * widget,GdkEvent * event,gpointer data);
void show_delete_event(GtkWidget *widget,gpointer data);

void ok_add_event(GtkWidget *widget,GdkEvent * event,gpointer data);
void cancel_add_event(GtkWidget *widget,gpointer data);

void confirm_addfriend_event(GtkWidget *widget,gpointer data);
void cancel_addfriend_event(GtkWidget *widget, gpointer data);

void ok_dele_event(GtkWidget *widget,gpointer data);
void cancel_dele_event(GtkWidget *widget,gpointer data);

void send_file_event(GtkWidget * widget,GdkEvent *event,gpointer data);

void send_file(GtkWidget * widget,GdkEvent *event, gpointer data);
void cancel_file(GtkWidget * widget, GdkEvent *event,gpointer data);
#endif // UI_H
